<?php
	Header("Content-Type: application/x-javascript");
	session_start();
	$con = mysql_connect("mysql.planetnorman.net","tc_calendar_user","cmsc345");
	mysql_select_db("tc_calendar", $con);
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}

	$results = mysql_query("SELECT * FROM occurrences natural join events;");

	$num = mysql_numrows($results);

        $i = 0;

	$array = array();
	$new = array();

	while($i < $num){
	
	$eid = mysql_result($results, $i, "eid");
	$cid = mysql_result($results, $i, "cid");
	$owner = mysql_result($results, $i, "owner");
	$subject = mysql_result($results, $i, "subject");
 	$description = mysql_result($results, $i, "description");
	$readonly = mysql_result($results, $i, "readonly");
	$catid = mysql_result($results, $i, "catid");
	$oid = mysql_result($results, $i, "oid");
	$startdate = mysql_result($results, $i, "startdate");
	$enddate = mysql_result($results, $i, "enddate");
	$starttime = mysql_result($results, $i, "starttime");
	$endtime = mysql_result($results, $i, "endtime");

	$array[$i] = array(id => $eid,
			title => $subject,
			start => $startdate,
			end => $enddate);

	$i++;
	}

	$jsonarray = json_encode($array);

	/*$jsonarray = str_replace("[", " ", $jsonarray);
	$jsonarray = str_replace("]", " ", $jsonarray);*/

	echo $jsonarray;
	
?>
